package com.example.micro.thread.demo;

import java.util.concurrent.TimeUnit;

public class ThreadLocalDemo {

    static ThreadLocal<Integer> t11 = new ThreadLocal<>();

    public static void main(String[] args) {
        try {

            new Thread(() -> {
                //t1
                try {
                    TimeUnit.SECONDS.sleep(3);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                System.out.println("线程1获取数据：" + t11.get());

            }).start();

            new Thread(() -> {
                //t2
                t11.set(new Integer(1));
            }).start();
        } finally {
            t11.remove();
        }
    }

}